install.packages("sf")
Installing package into ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'http://package-proxy/src/contrib/sf_0.9-2.tar.gz'
Content type 'application/x-tar' length 11180611 bytes (10.7 MB)
==================================================
downloaded 10.7 MB
* installing *binary* package ‘sf’ ...
* DONE (sf)
The downloaded source packages are in
‘/tmp/RtmpGfWAoA/downloaded_packages’
install.packages("rworldmap")
Error in install.packages : Updating loaded packages
library(tidyverse)
library(ggplot2)
library(plotly)
library(gganimate)
library(rworldmap)
#worldhap–> #world2020–>
world2020
worldhap
#Interactive Geom_col 1(Region:Happiness)
m<-ggplot(data= world2020,
mapping= aes(x = world2020$"Regional indicator" , y= world2020$"Ladder score", fill= world2020$"Country name"))+
geom_col() +
theme(axis.text.x = element_text (angle = 90), legend.position = "none")+
labs(x= "Region",y= "Happiness Ranking",
title = "Rankings for Every Region's Happiness Level",
subtitle="Year: 2020",
caption="Source: Kaggle- World Happiness Report 2020")
plot(m)
#Interactive Geom_col 2 (Economic:Happiness)
ggplot(data = world2020, aes(x = world2020$"Logged GDP per capita" , y = world2020$"Ladder score", fill = world2020$"Regional indicator"))+
geom_point(shape = 1)+
geom_smooth(method= lm, color = "pink")+
theme(axis.text.x = element_text (angle = 30))+
labs(title="Country's Economy vs. Their Happiness",
x= "GDP Per Capita",
y= "Happiness Score",
caption= "Source:Kaggle- World Happiness Report 2020")
ggplotly(p)
`geom_smooth()` using formula 'y ~ x'
#Interactive Graph 3 (Corruption: Life Expectancy)
p <-ggplot(data= world2020,
mapping= aes(x = world2020$"Regional indicator", y= world2020$"Perceptions of corruption", color = world2020$"Healthy life expectancy"))
p + geom_col() + guides(fill = FALSE)+
theme(axis.text.x = element_text (angle = 90))+
labs(x= "Region",y= "Corruptive Outlook",
title = "Corruption's Effect on Average Life Expectancy",
subtitle="Year: 2020",
caption="Source: Kaggle")
NA
#Interactive Geom_point 4 (Freedom:Positive Effect) #Add smoothing
p <- ggplot(data = worldhap, aes(x = Freedom , y =worldhap$"Positive affect", fill = worldhap$"Country (region)"))+
geom_point(shape = 1)+
geom_smooth(size = 0.5, method = "loess", se = FALSE)+
theme(legend.position = "none")+
labs(title="Freedom's Positive Effect Worldwide",
x= "Freedom Score",
y= "Positive Affect",
caption= "Source:Kaggle- World Happiness")
ggplotly(p)
`geom_smooth()` using formula 'y ~ x'
Removed 1 rows containing non-finite values (stat_smooth).
#Interactive Geom_Point 5(Generosity:Happiness)
p <- ggplot(data = world2020, aes(x = Generosity , y =world2020$"Ladder score", fill = world2020$"Country name"))+
geom_point(shape = 1)+
geom_smooth(method= lm, color = "pink")+
theme(legend.position = "none")+
labs(title="Generosity's Effect on Happiness Worldwide",
x= "Generosity Score",
y= "Happiness Score",
caption= "Source:Kaggle- World Happiness Report 2020")
ggplotly(p)
`geom_smooth()` using formula 'y ~ x'
#GGAnimate Graph 1 (Social Support:Generosity)
ggplot(world2020, aes(Generosity, world2020$"Social support", colour = world2020$"Regional indicator" ))+
geom_point() +
transition_states(
world2020$"Regional indicator",
transition_length = 3,
state_length= 1)+
enter_fade()+
exit_shrink()+
ease_aes('sine-in-out')+
theme(axis.text.x = element_text (angle = 90))+
#Here comes the gganimate code
labs(title="Worldwide Social Support vs. Generosity",
subtitle= "By Region: {closest_state}",
x= " Region's Generosity Score",
y= "Region's Social Support Rate",
caption= "Source: Kaggle- World Happiness 2020")
Frame 1 (1%)
Frame 2 (2%)
Frame 3 (3%)
Frame 4 (4%)
Frame 5 (5%)
Frame 6 (6%)
Frame 7 (7%)
Frame 8 (8%)
Frame 9 (9%)
Frame 10 (10%)
Frame 11 (11%)
Frame 12 (12%)
Frame 13 (13%)
Frame 14 (14%)
Frame 15 (15%)
Frame 16 (16%)
Frame 17 (17%)
Frame 18 (18%)
Frame 19 (19%)
Frame 20 (20%)
Frame 21 (21%)
Frame 22 (22%)
Frame 23 (23%)
Frame 24 (24%)
Frame 25 (25%)
Frame 26 (26%)
Frame 27 (27%)
Frame 28 (28%)
Frame 29 (29%)
Frame 30 (30%)
Frame 31 (31%)
Frame 32 (32%)
Frame 33 (33%)
Frame 34 (34%)
Frame 35 (35%)
Frame 36 (36%)
Frame 37 (37%)
Frame 38 (38%)
Frame 39 (39%)
Frame 40 (40%)
Frame 41 (41%)
Frame 42 (42%)
Frame 43 (43%)
Frame 44 (44%)
Frame 45 (45%)
Frame 46 (46%)
Frame 47 (47%)
Frame 48 (48%)
Frame 49 (49%)
Frame 50 (50%)
Frame 51 (51%)
Frame 52 (52%)
Frame 53 (53%)
Frame 54 (54%)
Frame 55 (55%)
Frame 56 (56%)
Frame 57 (57%)
Frame 58 (58%)
Frame 59 (59%)
Frame 60 (60%)
Frame 61 (61%)
Frame 62 (62%)
Frame 63 (63%)
Frame 64 (64%)
Frame 65 (65%)
Frame 66 (66%)
Frame 67 (67%)
Frame 68 (68%)
Frame 69 (69%)
Frame 70 (70%)
Frame 71 (71%)
Frame 72 (72%)
Frame 73 (73%)
Frame 74 (74%)
Frame 75 (75%)
Frame 76 (76%)
Frame 77 (77%)
Frame 78 (78%)
Frame 79 (79%)
Frame 80 (80%)
Frame 81 (81%)
Frame 82 (82%)
Frame 83 (83%)
Frame 84 (84%)
Frame 85 (85%)
Frame 86 (86%)
Frame 87 (87%)
Frame 88 (88%)
Frame 89 (89%)
Frame 90 (90%)
Frame 91 (91%)
Frame 92 (92%)
Frame 93 (93%)
Frame 94 (94%)
Frame 95 (95%)
Frame 96 (96%)
Frame 97 (97%)
Frame 98 (98%)
Frame 99 (99%)
Frame 100 (100%)
Finalizing encoding... done!
#GGAnimate Graph 2 (Discussion Point Plot)
ggplot(world2020, aes(world2020$"Ladder score", world2020$"Healthy life expectancy", colour = world2020$"Regional indicator"))+
geom_point(alpha = 0.5)+
transition_states(world2020$"Regional indicator",
transition_length = 2,
state_length= 1)+
scale_size(range = c(2,15))+
scale_x_log10() +
facet_wrap(~world2020$"Regional indicator")+
labs(title="World Happiness vs. Worldly Life Expectancy",
subtitle= "By Region: {closest_state}",
x= "Happiness Score",
y= "Life Expectancy",
caption= "Source: Kaggle- World Happiness 2020")
Frame 1 (1%)
Frame 2 (2%)
Frame 3 (3%)
Frame 4 (4%)
Frame 5 (5%)
Frame 6 (6%)
Frame 7 (7%)
Frame 8 (8%)
Frame 9 (9%)
Frame 10 (10%)
Frame 11 (11%)
Frame 12 (12%)
Frame 13 (13%)
Frame 14 (14%)
Frame 15 (15%)
Frame 16 (16%)
Frame 17 (17%)
Frame 18 (18%)
Frame 19 (19%)
Frame 20 (20%)
Frame 21 (21%)
Frame 22 (22%)
Frame 23 (23%)
Frame 24 (24%)
Frame 25 (25%)
Frame 26 (26%)
Frame 27 (27%)
Frame 28 (28%)
Frame 29 (29%)
Frame 30 (30%)
Frame 31 (31%)
Frame 32 (32%)
Frame 33 (33%)
Frame 34 (34%)
Frame 35 (35%)
Frame 36 (36%)
Frame 37 (37%)
Frame 38 (38%)
Frame 39 (39%)
Frame 40 (40%)
Frame 41 (41%)
Frame 42 (42%)
Frame 43 (43%)
Frame 44 (44%)
Frame 45 (45%)
Frame 46 (46%)
Frame 47 (47%)
Frame 48 (48%)
Frame 49 (49%)
Frame 50 (50%)
Frame 51 (51%)
Frame 52 (52%)
Frame 53 (53%)
Frame 54 (54%)
Frame 55 (55%)
Frame 56 (56%)
Frame 57 (57%)
Frame 58 (58%)
Frame 59 (59%)
Frame 60 (60%)
Frame 61 (61%)
Frame 62 (62%)
Frame 63 (63%)
Frame 64 (64%)
Frame 65 (65%)
Frame 66 (66%)
Frame 67 (67%)
Frame 68 (68%)
Frame 69 (69%)
Frame 70 (70%)
Frame 71 (71%)
Frame 72 (72%)
Frame 73 (73%)
Frame 74 (74%)
Frame 75 (75%)
Frame 76 (76%)
Frame 77 (77%)
Frame 78 (78%)
Frame 79 (79%)
Frame 80 (80%)
Frame 81 (81%)
Frame 82 (82%)
Frame 83 (83%)
Frame 84 (84%)
Frame 85 (85%)
Frame 86 (86%)
Frame 87 (87%)
Frame 88 (88%)
Frame 89 (89%)
Frame 90 (90%)
Frame 91 (91%)
Frame 92 (92%)
Frame 93 (93%)
Frame 94 (94%)
Frame 95 (95%)
Frame 96 (96%)
Frame 97 (97%)
Frame 98 (98%)
Frame 99 (99%)
Frame 100 (100%)
Finalizing encoding... done!
#Map 1 (Top 10 Happiest Countries)
library(maptools)
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
data=(wrld_simpl)
myCountries = wrld_simpl@data$NAME %in% c("Finland", "Denmark", "Norway", "Iceland", "Sweden", "Netherlands", "New Zealand", "Switzerland", "Austria", "Canada")
plot(wrld_simpl, col = c(gray(.80), "yellow")[myCountries+1])
#Map 2 (Finland- Happiest Place on Earth)
library(maptools)
data=(wrld_simpl)
myCountries = wrld_simpl@data$NAME %in% c("Finland")+
#choose the desired nation(s) you would like to highlight
plot(wrld_simpl, col = c(gray(.80), "yellow")[myCountries+1])
#Plot 10! World Happiness Pie Chart
library(plotly)
pie <- plot_ly(world2020, labels = ~world2020$"Regional indicator", type = 'pie')
pie <- pie %>% layout(title = 'World Happiness Composition',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
pie